package com.jt.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class LogAspect {
    //定义切入点
    @Pointcut("@annotation(com.jt.annotation.RequiredLog)")
    public void doLog(){}//锦上添花的锦(注解描述的方法)

    //定义扩展业务逻辑
    @Around("doLog()")
    //@Around("@annotation(com.jt.resource.annotation.RequiredLog)")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.debug("Before {}",System.currentTimeMillis());
        Object result=joinPoint.proceed();//执行执行链(其它切面,目标方法-锦)
        log.debug("After {}",System.currentTimeMillis());
        return result;//目标方法(切入点方法)的执行结果
    }
}

